<?php  
require_once($_SERVER['DOCUMENT_ROOT']."/defaultconf.mex");
$GET = explode('.',$_GET['IMG']); 
$GETFILE = $GET[0];
$GETEXT = $GET[1];
$PRXFILE = $GLOBALS['DOC'].'CCENTDOC/'.$_GET['IMG'];

$altFile = utf8_decode($PRXFILE);
if (file_exists($altFile) && is_readable($altFile)) {
$PRXFILE = $altFile;
}
  if (file_exists($PRXFILE) && is_readable($PRXFILE)) {
    $ext = $GETEXT;
    switch ($ext) {
      case 'jpg':
        $mime = 'image/jpeg';
        break;
      case 'bmp':
        $mime = 'image/bmp';
        break;
      case 'jpeg':
        $mime = 'image/jpeg';
        break;
      case 'gif':
        $mime = 'image/gif';
        break;
      case 'doc':
        $mime = 'application/msword';
        break;
      case 'xls':
        $mime = 'application/vnd.ms-excel';
        break;
      case 'docx':
        $mime = 'application/msword';
        break;
      case 'png':
        $mime = 'image/png';
        break;
      case 'pdf':
        $mime = 'application/pdf ';
        break;
      default:
        $mime = true;
    }

      header('Content-type: '.$mime);
      header('Content-length: '.filesize($PRXFILE));
      header('Content-Disposition: attachment; filename="'.$_GET['IMG'].'"');
      $file = @ fopen($PRXFILE, 'rb');

      fpassthru($file);
      exit;
  } ?>